<template>
  <div class="person">
    姓：<input type="text" v-model="firstName"><br>
    名：<input type="text" v-model="lastName"><br>
    全名：<span>{{ fullName }}</span><br>
    <button @click="changeFullName">将全名改为:</button>
  </div>
</template>

<script setup name="Person">
import { computed, ref } from 'vue'

let firstName = ref('小')
let lastName = ref('宇')

let fullName = computed({
  get() {
    return firstName.value + lastName.value
  },
  set(value) {
    let names = value.split('-')
    firstName.value = names[0]
    lastName.value = names[1]
  }
})

function changeFullName() {
  fullName.value = '小-福'
}
</script>

<style>
.person {
  background-color: burlywood;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 10px;
  color: black; /* 设置字体颜色为黑色 */
}
</style>
